import Vue from 'vue'

Vue.directive('jjoao', {
  inserted (el) {
    // console.log(el);
    el.focus()
    if (['INPUT', 'TEXTAREA'].indexOf(el.tagName) !== -1) {
      el.focus()
    } else {
      let node = el.querySelector('input')
      if (node) {
        node.focus()
        return
      }
      node = el.querySelector('textarea')
      if (node) {
        node.focus()
        return
      }
      throw new Error('请把jujiao加载在textarea上')
    }
  },
  update (el) {
    // console.log(el);
    el.focus()
    if (['INPUT', 'TEXTAREA'].indexOf(el.tagName) !== -1) {
      el.focus()
    } else {
      let node = el.querySelector('input')
      if (node) {
        node.focus()
        return
      }
      node = el.querySelector('textarea')
      if (node) {
        node.focus()
        return
      }
      throw new Error('请把jujiao加载在textarea上')
    }
  },
})
